<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<title>错误码日志统计</title>
<div class="lay-box">

    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

<style>
    .lay-box {
        padding: 8px 12px;
    }

    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.enable== 1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    var startDate = "${star}";
    var endDate = "${end}";
    var searchKey = "";
    var tableIns;
    var ids = "";
    var form;
    var table = "sdk_error_log";
    layui.use('table', function () {
        tableIns = layui.table,
            form = layui.form;
        form.render();
        tableIns.render({
            elem: '#layTable'
            ,
            url:  '/sys/sdkerrorlog/errorcount'
            ,
            method: 'POST'
            ,
            where: {
                'star': startDate,
                'end': endDate,
            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {
                    field: 'errorCount',
                    title: '错误数量',
                    width: 410,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'sdkKey',
                    title: '收支分类',
                    width: 410,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'errorCode',
                    title: '错误码',
                    width: 410,
                    align: 'center',
                    sort: true
                }
                , {
                    field: 'errorMsg',
                    title: '错误信息',
                    width: 415,
                    align: 'center',
                    sort: true
                }
            ]]
            ,
            page: true
        });

        form.on('switch(sexDemo)', function (obj) {
            // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
            if (obj.elem.checked) {
                commonenable(this.value, 1);
            } else {
                commonenable(this.value, 0);
            }

        });
        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/sys/sdkerrorlog/delete",
                    type: 'post',
                    data: { "id": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            search();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'save') {
                layer.prompt({
                    formType: 2,
                    value: '30',
                    title: '请输入CD时间(分钟)',
                    area: ['300px', '350px'] //自定义文本域宽高
                }, function(value, index, elem){
                    $.ajax({
                        url: "/sys/aderrorconfig/addfor",
                        type: 'post',
                        data: { "sdkKey": data.sdk_key,"errorCode": data.error_code,"errorMsg": data.error_msg,time:value},
                        async: false,
                        dataType: "json",
                        success: function (req) {
                            if (req.success) {
                                layer.msg(req.message, {icon: 1})
                            } else {
                                layer.msg(req.message, {icon: 2})
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });

    function search() {

        tableIns.reload('dataTableId', {
            where: {
                table: table,
                query: {},
                time: {'start': startDate, 'end': endDate}

            }
            , page: {}
        });
    }




    function gradeEdit() {
        layer_show("新增", "/sys/sdkerrorlog/add", "650", "600");
    }
    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status) {
        $.ajax({
            url: "/common/commonSwitch",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": "has_deleted"},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }


</script>
<!--/请在上方写此页面业务相关的脚本-->
